﻿using FormsAuthWeb.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.Adapters;
using System.Web.UI.WebControls;

namespace FormsAuthWeb
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [SubmitMethod(AutoRedirect = true)]
        public void UserLogin()
        {
            string loginName = Request.Form["LoginName"];
            if (String.IsNullOrEmpty(loginName))
            {
                return;
            }
            FormsAuthentication.SetAuthCookie(loginName, true);

            TryRedirect();
        }

        private void TryRedirect()
        {
            string returnUrl = Request.QueryString["ReturnUrl"];
            if (String.IsNullOrEmpty(returnUrl))
            {
                Response.Redirect("~/Index.aspx");
            }
            else
            {
                Response.Redirect(returnUrl);
            }
        }
    }
}